package cn.yudao.basic.controller;

import cn.yudao.basic.dto.LoginDto;
import cn.yudao.basic.dto.WxDto;
import cn.yudao.basic.exception.BusinessException;
import cn.yudao.basic.service.ILoginService;
import cn.yudao.basic.utils.AjaxResult;
import cn.yudao.org.domain.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService iLoginService;


    /**
    * @Title: loginAccount
    * @Description: 账号登录
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/7/8 21:56
    * @Parameters:
    * @Return
    */
    @PostMapping("/account")
    public AjaxResult loginAccount(@RequestBody LoginDto loginDto){
        try {
            Map<String,Object> map =  iLoginService.loginAccount(loginDto);
            return AjaxResult.me().setResult(map);
        }catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙");
        }
    }

    /**
    * @Title: loginAccount
    * @Description: 手机验证码登录
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/7/8 21:56
    * @Parameters:
    * @Return
    */
    @PostMapping("/phoneCode")
    public AjaxResult loginPhoneCode(@RequestBody LoginDto loginDto){
        try {
            Map<String,Object> map =  iLoginService.loginPhoneCode(loginDto);
            return AjaxResult.me().setResult(map);
        }catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙");
        }
    }


    /**
    * @Title: wechat
    * @Description: 微信登录
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/7/10 17:52
    * @Parameters:
    * @Return
    */
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody WxDto wxDto){
        try {
            return iLoginService.wechat(wxDto);
        }catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙");
        }
    }

    /**
    * @Title: wechat
    * @Description: 微信绑定
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/7/10 17:53
    * @Parameters:
    * @Return
    */
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody WxDto wxDto){
        try {
            Map map =  iLoginService.wechatBinder(wxDto);
            return AjaxResult.me().setResult(map);
        }catch (BusinessException e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙");
        }
    }
}
